<template>
  <div>
    <Header></Header>
    <div class="main">
      <div class="top-left">所有订单</div>
      <div class="top">
        <span style="margin-left: 120px">商品信息</span>
        <span style="margin-left: 152px">单价</span>
        <span style="margin-left: 66px">数量</span>
        <span style="margin-left: 66px">总价</span>
        <span style="margin-left: 66px">状态</span>
      </div>
      <el-table
        ref="multipleTable"
        :data="item.order_has_items"
        tooltip-effect="dark"
        style="width: 100%; padding-bottom: 20px"
        v-for="(item, index) in orderList"
        :key="index"
        @click.native="Click(item)"
      >
        <el-table-column
          :label="'订单号 ' + item.orderId + ' 时间 ' + item.time"
          width="300"
        >
          <template slot-scope="scope">
            <div class="wrapper">
              <img :src="`http://localhost:8080/api/v1/images/${scope.row.item.imageDir}/thumbnail.jpg`" alt="" />
              <span>{{ scope.row.item.name }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column width="100" align="center">
          <template slot-scope="scope">￥{{ scope.row.item.price }}</template>
        </el-table-column>
        <el-table-column width="100" align="center">
          <template slot-scope="scope">{{ scope.row.amount }}</template>
        </el-table-column>
        <el-table-column width="100" align="center">
          <template slot-scope="scope"
            >￥{{ (scope.row.item.price * scope.row.amount) | rounding }}</template
          >
        </el-table-column>
        <el-table-column width="100" align="center">
          <template>{{ item.status }}</template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import Header from '@/components/Header.vue'

export default {
  components: {
    Header
  },
  data () {
    return {
      orderList: []
    }
  },
  methods: {
    Click (item) {
      this.$router.push({ name: 'OrderDetail', params: { item: item } })
    }
  },
  filters: {
    rounding (val) {
      return val.toFixed(2)
    }
  },
  mounted () {
    this.$http.get('order', {
      params: {
        userId: JSON.parse(this.$cookie.get('userInfo')).userId
      }
    }).then((res) => {
      this.orderList = res.data
      console.log(res)
    })
  }
}
</script>

<style lang="less" scoped>
.main {
    width: 50%;
    margin: 20px auto;
    .top-left {
      width: 18%;
      height: 100%;
      border-bottom: 1px solid #f40;
      font-size: 24px;
      color: #f40;
      text-align: center;
      line-height: 50px;
    }
  .top {
    width: 100%;
    height: 50px;
    line-height: 50px;
    background-color: rgb(243, 168, 140);
    span {
      color: black;
    }
  }
  .wrapper {
    display: flex;
    img {
      width: 80px;
      height: 80px;
    }
    span {
      padding-left: 10px;
      font-size: 10px;
      flex: 1;
    }
  }
}
</style>
